package com.example.spring.demo.common.error;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2024/12/25 21:41
 **/
public class CustomException extends RuntimeException{
    private final String errorCode;
    private final String message;

    /*
    兜底异常
     */
    public CustomException() {
        this.errorCode = ErrorCodeEnum.SYSTEM_ERROR.getErrorCode();
        this.message = ErrorCodeEnum.SYSTEM_ERROR.getErrorMessage();
    }

    public CustomException(String errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
        this.message = message;
    }

    public CustomException(ErrorCodeEnum errorCodeEnum) {
        this.errorCode = errorCodeEnum.getErrorCode();
        this.message = errorCodeEnum.getErrorMessage();
    }

    public CustomException(String errorMessage) {
        this.errorCode = ErrorCodeEnum.TEST_CUSTOM_ERROR.getErrorCode();
        this.message = errorMessage;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public String getMessage() {
        return message;
    }
}
